<!--<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=5eZINTQBxw6GVqCDPSNekac6L1coexBr"></script>-->
<div id="map" style="display:none;">
  <div id="search-container">
    <div class="search-product-form">
      <div class="search-product-inner">
            <span class="search-icon">
              <img src="/root/search.png" alt="Search">
            </span>

        <div class="search_input_div">
          <input class="search_input" id="suggestId" placeholder="搜索" required="" type="search">
        </div>
      </div>
    </div>
  </div>

  <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
  <div id="l-map"></div>
  <div id="r-result-text"></div>
</div>
<script type="text/javascript">
  /////触发最新的下拉数据列表
  function get_local_address(points) {
    var mOption = {poiRadius: 500, numPois: 10}
    var myGeo = new BMap.Geocoder();
    myGeo.getLocation(points, function mCallback(rs) {
          var allPois = rs.surroundingPois;

          var returntext = "<div class='weui_cells weui_cells_access'>";
          for (i = 0; i < allPois.length; ++i) {
            returntext += "  <a class='weui_cell' href='#' onclick='get_address_analysis(\"" + allPois[i].address+allPois[i].title + "\",\"" + allPois[i].point.lng + "\",\"" + allPois[i].point.lat + "\")' > <div class='weui_cell_bd weui_cell_primary'> <p>" + allPois[i].title + "</p> </div><div class='weui_cell_ft'></div> </a>"
          }
          returntext += "</div>";
          document.getElementById("r-result-text").innerHTML = returntext;
        }, mOption
    );
  }

  /////这里进行位置到经纬度的解析
  function get_address_analysis(address, lng, lat) {
    document.getElementById('latitude').value = lat;
    document.getElementById('longitude').value = lng;
    document.getElementById('address').value = address;
    $("#address_info #address_show").text(address);
    ///显示地图框
    $("#map").hide();
    $(".container").show();
  }
</script>
<script type="text/javascript">
  //弹出地图
  function alert_map() {
    ///显示地图框
    $(".container").hide();
    $("#map").show();

// 百度地图API功能
    var map = new BMap.Map("l-map");
///允许放大缩小
    map.enableScrollWheelZoom(true);
//双击放大地图
    map.enableDoubleClickZoom(true);
// 定义一个中心标示   定义一个位置用于悬浮一个标志
    function ZoomControl() {
      this.defaultAnchor = BMAP_ANCHOR_TOP_LEFT;
      this.defaultOffset = new BMap.Size((map.getSize().width / 2) - 20, (map.getSize().height / 2) - 40);
    }

/////定一个图标样式
    ZoomControl.prototype = new BMap.Control();
    ZoomControl.prototype.initialize = function (map) {
      var div = document.createElement("div");
      div.innerHTML = "<img src ='/root/icon_map.png'/>";
      div.style.cursor = "pointer";
      div.style.height = "40px";
      map.getContainer().appendChild(div);
      return div;
    }
    var myZoomCtrl = new ZoomControl();
    map.addControl(myZoomCtrl);
/////添加回调函数
    translateCallback = function (data) {
      if (data.status == 0) {
        var points = new BMap.Point(data.points[0].lng, data.points[0].lat); // 创建点坐标
        map.centerAndZoom(points, 20);
///////添加定位控件
        var marker = new BMap.Marker(points);  // 创建标注
        map.addOverlay(marker);               // 将标注添加到地图中
        marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
/////////获取下拉数据列表
        get_local_address(new BMap.Point(data.points[0].lng, data.points[0].lat))
      }
    }
    //转换gps到百度地图图标  并且在一个位置上显示
    var convertor = new BMap.Convertor();
    var pointArr = [];
    pointArr.push(new BMap.Point( document.getElementById('longitude').value , document.getElementById('latitude').value ));
    convertor.translate(pointArr, 1, 5, translateCallback)
///地图拖拽完成后触发
    map.addEventListener("touchend", function () {
      var points = new BMap.Point(map.getCenter().lng, map.getCenter().lat); // 创建点坐标
      map.centerAndZoom(points, 16);
      get_local_address(points)
    });
//////////////////提示输入框
// 百度地图API功能
    function G(id) {
      return document.getElementById(id);
    }

    var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
        {
          "input": "suggestId"
          , "location": map
        });
    var myValue;
    ac.addEventListener("onconfirm", function (e) {    //鼠标点击下拉列表后的事件
      var _value = e.item.value;
      myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
      map.centerAndZoom(myValue, 16);
      document.getElementById("searchResultPanel").innerHTML = "";
      var myGeo = new BMap.Geocoder();
// 将地址解析结果显示在地图上,并调整地图视野
      myGeo.getPoint(myValue, function (point) {
        if (point) {
          get_local_address(point)
        }
      }, _value.city);
    });


  }
</script>




